package com.meibei.ljl.mymusic.ui.home.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.meibei.ljl.mymusic.R;
import com.meibei.ljl.mymusic.base.BaseActivity;
import com.meibei.ljl.mymusic.ui.home.fragment.HomeFragment;
import com.meibei.ljl.mymusic.ui.home.fragment.MyCircleFragment;
import com.meibei.ljl.mymusic.ui.home.fragment.MyMusicFragment;
import com.meibei.ljl.mymusic.ui.widget.MyPageAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private MyPageAdapter myPageAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        tabLayout = (TabLayout) findViewById(R.id.first_page_tablayout);
        viewPager = (ViewPager) findViewById(R.id.first_page_vp);
    }

    @Override
    public void setListener() {

    }

    @Override
    public void initData() {
        List<Fragment> fragments = new ArrayList<>(3);
        String[] names = getResources().getStringArray(R.array.TabTitles);
        fragments.add(new HomeFragment());
        fragments.add(new MyMusicFragment());
        fragments.add(new MyCircleFragment());
        myPageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments, names);
        viewPager.setAdapter(myPageAdapter);
        tabLayout.setupWithViewPager(viewPager);//将TabLayout和ViewPager关联起来
    }
}
